package io.github.yotta.dict.web.controller;

import io.github.yotta.common.api.model.IdRequest;
import io.github.yotta.common.web.extension.LoginUserLoadProvider;
import io.github.yotta.common.web.extension.TenantResolveProvider;
import org.springframework.web.bind.annotation.*;
import lombok.RequiredArgsConstructor;
import io.github.yotta.dict.api.service.SysDictService;
import io.github.yotta.dict.server.converter.SysDictConverter;
import io.github.yotta.dict.api.param.SysDictAddParam;
import io.github.yotta.dict.api.param.SysDictUpdateParam;

import javax.servlet.http.HttpServletRequest;

/**
* @author yotta-generator
* @date 2025-08-11 10:12:20
* 系统字典表 - 控制器
*/
@SuppressWarnings("unused")
@RestController
@RequestMapping("/sysDict")
@RequiredArgsConstructor
public abstract class SysDictWriteController {

    private final SysDictService sysDictService;
    private final TenantResolveProvider tenantResolveProvider;
    private final LoginUserLoadProvider loginUserLoadProvider;

    @PostMapping
    public Boolean save(
            HttpServletRequest request, @RequestBody SysDictAddParam sysDictAddParam) {
        String tenantId = tenantResolveProvider.loadTenantId(request);
        sysDictAddParam.setTenantId(tenantId);
        sysDictAddParam.setCreatedBy(loginUserLoadProvider.get( request).getId());
        sysDictAddParam.checkValid();
		return sysDictService.save(sysDictAddParam);
    }


    @PutMapping
    public Boolean updateById(HttpServletRequest request, @RequestBody SysDictUpdateParam sysDictUpdateParam) {
        String tenantId = tenantResolveProvider.loadTenantId(request);
        sysDictUpdateParam.setUpdatedBy(loginUserLoadProvider.get( request).getId());
        sysDictUpdateParam.setTenantId(tenantId);
        sysDictUpdateParam.checkValid();
		return sysDictService.updateById(sysDictUpdateParam);
    }
    @DeleteMapping()
    public Boolean removeById(HttpServletRequest request, @RequestBody IdRequest idParam) {
        String tenantId = tenantResolveProvider.loadTenantId(request);
        idParam.setTenantId(tenantId);
		return sysDictService.removeById(idParam);
    }







}
